import { logger } from '../services/logger'
import type { WorkflowTemplate } from '../types/workflow'

// 验证工作流配置
export const validateWorkflow = (workflow: any): boolean => {
    try {
        // 验证基本结构
        if (!workflow || typeof workflow !== 'object') {
            logger.warn('Invalid workflow: not an object')
            return false
        }

        // 验证节点
        if (!workflow.nodes || !Array.isArray(workflow.nodes)) {
            logger.warn('Invalid workflow: nodes not found or not an array')
            return false
        }

        // 验证连接
        if (!workflow.edges || !Array.isArray(workflow.edges)) {
            logger.warn('Invalid workflow: edges not found or not an array')
            return false
        }

        return true
    } catch (error) {
        logger.error('Workflow validation failed:', error)
        return false
    }
}

// 验证工作流模板
export const validateTemplate = (template: WorkflowTemplate): boolean => {
    try {
        // 验证版本
        if (!template.version) {
            logger.warn('Invalid template: version not found')
            return false
        }

        // 验证参数
        if (!Array.isArray(template.params)) {
            logger.warn('Invalid template: params not found or not an array')
            return false
        }

        // 验证参数配置
        for (const param of template.params) {
            if (!param.id || !param.type || !param.label) {
                logger.warn('Invalid template: invalid param configuration', param)
                return false
            }
        }

        // 验证布局
        if (!template.layout || !Array.isArray(template.layout.groups)) {
            logger.warn('Invalid template: invalid layout configuration')
            return false
        }

        return true
    } catch (error) {
        logger.error('Template validation failed:', error)
        return false
    }
} 